package com.iee.patterns.example.event_obv.obv_base;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.EventObject;
import java.util.List;
import java.util.stream.Collectors;

/**
 *@ClassName Demo
 *@Description TODO
 *@Author longxiaonan@163.com
 *@Date 2022/3/23 0023 19:32
 */
public class Demo {

    public static void main(String[] args) {
        List<AbstractEventListener> listeners = new ArrayList<>(3);
        listeners.add(new Test1EventListener(2));
        listeners.add(new Test2EventListener(1));
        listeners.add(new Test3EventListener(3));

        listeners = listeners.stream()
                .sorted(Comparator.comparing(AbstractEventListener::getOrder))
                .collect(Collectors.toList());
        EventMulticaster eventMulticaster = new EventMulticaster(listeners);
        Order order = new Order("aa11");
        EventObject eventObject = new EventObject(order);

        eventMulticaster.multicastEvent(new OrderCallbackEvent(eventObject));
    }
}
